//
//  BKXMainTabbarController.swift
//  微博
//
//  Created by 田凯 on 16/4/16.
//  Copyright © 2016年 田凯. All rights reserved.
//

import UIKit

class BKXMainTabbarController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        //初始化tabbar
        let tabbar = BKXTabBar()
        //设置控制器为tababr的代理
        tabbar.bkxDelegate = self
        
        
//        self.tabBar = tabBar  错的  系统私有属性  不能直接设置
        //通过kvc 来设置
        setValue(tabbar, forKey: "tabBar")
        
        
        //设置子控制器
        addChildViewController(BKXHomeViewController(), imagName: "tabbar_home", title: "首页")
        
        addChildViewController(BKXMessageViewController(), imagName: "tabbar_message_center", title: "消息")
        addChildViewController(BKXDiscoverViewController(), imagName: "tabbar_discover", title: "发现")
        addChildViewController(BKXProfileViewController(), imagName: "tabbar_profile", title: "我的")
        
    }
    // MARK: - 添加子控制器的方法
    func addChildViewController(childController: UIViewController,imagName: String,title: String) {
        
        //设置图片
        childController.tabBarItem.image = UIImage(named: imagName)
        //设置选中图片
        childController.tabBarItem.selectedImage = UIImage(named: "\(imagName)_selected")
        //设置title
        childController.title = title
        //添加子控制器
//        addChildViewController(UINavigationController(rootViewController: childController))
        let a = UINavigationController(rootViewController: childController)
        addChildViewController(a)
    }
    
    

  }

extension BKXMainTabbarController: BKXTabBarDelegate{
    func composeButtonDelegateClick() {
        print("去去去")
        presentViewController(UINavigationController(rootViewController: BKXComposeViewController()), animated: true, completion: nil)
        
    }

}
